package com.fadadianqi.commons;

import com.yeqiangwei.commons.net.URL;
import com.yeqiangwei.commons.net.URL.Charset;
import com.yeqiangwei.commons.util.ParamUtils;

import javax.servlet.http.HttpServletRequest;

import static com.yeqiangwei.commons.util.StringHelper.EMPTY;

public class BackToURLUtils {

    public static final String DEFAULT_BACK_URL = "backURL";

    public static final void setCurrentURLToAttr(HttpServletRequest request,
                                                 String key) {
        String backURL = ParamUtils.getRequestURL(request, EMPTY);
        request.setAttribute(key, URL.encode(backURL, Charset.UTF8, EMPTY));
    }

    public static final void setParamURLToAttr(HttpServletRequest request
            , String key) {
        request.setAttribute(key, ParamUtils.getString(request, key, EMPTY));
    }
}
